<template>
  <!-- 确认告警 表单 -->
  <a-modal
    v-model:open="visible"
    title="确认告警"
    class="addRule"
    destroyOnClose
    :width="520"
    @cancel="cancel"
    centered
  >
    <a-form
      :model="confirmForm"
      layout="inline"
      :labelCol="{ style: { width: '100px' } }"
      ref="formRef"
    >
      <a-form-item label="确认内容：" :rules="[{ required: true }]">
        <a-textarea
          v-model:value="confirmForm.message"
          class="formInput"
          placeholder="请输入"
          allow-clear
          :style="{ height: '100px' }"
        />
      </a-form-item>
    </a-form>

    <template #footer>
      <div class="footerBar">
        <a-button key="back" @click="cancel">取消</a-button>
        <a-button
          key="submit"
          type="primary"
          :loading="loading"
          @click="handleSubmit"
          >确认</a-button
        >
      </div>
    </template>
  </a-modal>
</template>

<script setup>



const $api = inject("$api");
const props = defineProps({
  confirmWarnVisible: Boolean,
  rowData: {
    type: Object,
  },
});

const loading = ref(false);
const visible = ref(props.confirmWarnVisible);
const formRef = ref(null);

const confirmForm = ref({
  id: props.id,
  message: null,
});

const emits = defineEmits([
  "update:confirmWarnVisible",
  "getStorageChargingList",
]);

watch(
  () => props.confirmWarnVisible,
  (val) => {
    visible.value = val;
  }
);

watch(
  () => props.id,
  (val) => {
    confirmForm.value.id = val;
  },
  { immediate: true }
);

const cancel = () => {
  emits("update:confirmWarnVisible", false);
  confirmForm.value = {
    message: null,
  };
};

const handleSubmit = async () => {
  loading.value = true;
  const params = {
    id: props.rowData.id,
    message: confirmForm.value.message
  }
  const res = await $api.chargeEvtWarnConfirm(params);
  loading.value = false;
  if (res.code === 0) {
    message.success("确认成功");
    emits("getStorageChargingList");
    cancel();
  }
};
</script>

<style lang="less" scoped>
.formInput {
  width: 350px;
}

.ant-form-item {
  margin-top: 20px;
}

.footerBar {
  text-align: center;
  margin-top: 30px;
}

.areaSelect {
  display: inline-block;
  width: 113px;
  margin-right: 5px;

  &:last-child {
    margin-right: 0;
  }
}
</style>
